﻿<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Sửa đề bài</title>
</head>
<body>
<?php 
require_once("../include/db_info.inc.php"); 
require_once("admin-header.php");
require_once("../maincore.php");
include_once("../fckeditor/fckeditor.php") ;
if(isset($_GET['id'])){
	//require_once("../include/check_get_key.php");
$sql="SELECT * FROM `problem` WHERE `problem_id`=".intval($_GET['id'])." and author_id='$mtid'";
$result=mysql_query($sql);
$row=mysql_fetch_object($result);
if ($row<1) die("Không thể sửa");
$basedir=$OJ_DATA."/$id";
?>
<center><h1>Sửa bài - quản lí bộ test</h1></center>

<input type='hidden' name='problem_id' value='New Problem'>
<p>Mã đề bài: <?php echo $row->problem_id?></p>
<input type='hidden' name='problem_id' value='<?php echo $row->problem_id?>'>
<p>Tiêu đề: <?php echo htmlspecialchars($row->title)?></p>
<?php
$test_id=1;
while (file_exists($basedir."/test$test_id.in")) {
	echo "<h2>Test <b>$test_id</b> </h2>: [<a href='".MYSELF."?pid=$row->problem_id&del=$test_id'>Xóa</a>]<br>";
	echo "<h3>Input:</h3>";
	$fin = fopen($basedir."/test$test_id.in","r");
	$content = fread($fin,filesize($fin));
	fclose($fin);
	echo "<div class=content>".$content."</div>";
	echo "<h3>Output:</h3>";
	$fout = fopen($basedir."/test$test_id.out","r");
	$content = fread($fout,filesize($fout));
	echo "<div class=content>".$content."</div>";
	fclose($fout);
}
echo "<h2>Thêm bộ test </h2>:";
echo "<form method='POST' action='".MYSELF."'>";
?>
</form>

exit(0);
<?php
$description = new FCKeditor('description') ;
$description->BasePath = '../fckeditor/' ;
$description->Height = 400 ;
$description->Width=600;

$description->Value = $row->description ;
$description->Create() ;
?>
</p>

<p align=left><h3>Input:</h3>

<?php
$input = new FCKeditor('input') ;
$input->BasePath = '../fckeditor/' ;
$input->Height = 200 ;
$input->Width=600;

$input->Value = $row->input ;
$input->Create() ;
?>
</p>

</p>
<p align=left><h3>Output:</h3>


<?php
$output = new FCKeditor('output') ;
$output->BasePath = '../fckeditor/' ;
$output->Height = 200 ;
$output->Width=600;

$output->Value = $row->output;
$output->Create() ;
?>
<h3>Ví dụ:</h3>
<p>*Input:<br><textarea rows=4 name=sample_input cols=70><?php echo htmlspecialchars($row->sample_input)?></textarea></p>
<p>*Output:<br><textarea rows=3 name=sample_output cols=70><?php echo htmlspecialchars($row->sample_output)?></textarea></p>
<p><h3>Lưu ý:</h3>
<?php
$output = new FCKeditor('hint') ;
$output->BasePath = '../fckeditor/' ;
$output->Height = 200 ;
$output->Width=600;
$output->Value = $row->hint;
$output->Create() ;
?>
</p>
<!--
<p>Chấm riêng: 
N<input type=radio name=spj value='0' <?php echo $row->spj=="0"?"checked":""?>>
Y<input type=radio name=spj value='1' <?php echo $row->spj=="1"?"checked":""?>></p>
-->
<input type='hidden' name=spj value='0' >
<p><h3>Mã nguồn:</h3><textarea name=source rows=1 cols=70><?php echo htmlspecialchars($row->source)?></textarea></p>


<input type='submit' value='Lưu thay đổi' name='submit'>
</form>
<p>
<?php require_once("../oj-footer.php"); 
} else {
	//require_once("../include/check_post_key.php");
	$id=$_POST['problem_id'];
	$title=$_POST['title'];
	$time_limit=$_POST['time_limit'];
	$memory_limit=$_POST['memory_limit'];
	$description=$_POST['description'];
	$input=$_POST['input'];
	$output=$_POST['output'];
	$sample_input=$_POST['sample_input'];
	$sample_output=$_POST['sample_output'];
	$hint=$_POST['hint'];
	$source=$_POST['source'];
	$spj=$_POST['spj'];
	if (get_magic_quotes_gpc ()) {
		$title = stripslashes ( $title);
		$time_limit = stripslashes ( $time_limit);
		$memory_limit = stripslashes ( $memory_limit);
		$description = stripslashes ( $description);
		$input = stripslashes ( $input);
		$output = stripslashes ( $output);
		$sample_input = stripslashes ( $sample_input);
		$sample_output = stripslashes ( $sample_output);
		$hint = stripslashes ( $hint);
		$source = stripslashes ( $source); 
		$spj = stripslashes ( $spj);
		$source = stripslashes ( $source );
	}
	
	echo "Sample data file in $basedir Updated!<br>";
		if($sample_input){
			$fp=fopen($basedir."/sample.in","w");
			fputs($fp,preg_replace("(\r\n)","\n",$sample_input));
			fclose($fp);
			$fp=fopen($basedir."/sample.out","w");
			fputs($fp,preg_replace("(\r\n)","\n",$sample_output));
			fclose($fp);
		}
	$title=mysql_real_escape_string($title);
	$time_limit=mysql_real_escape_string($time_limit);
	$memory_limit=mysql_real_escape_string($memory_limit);
	$description=mysql_real_escape_string($description);
	$input=mysql_real_escape_string($input);
	$output=mysql_real_escape_string($output);
	$sample_input=mysql_real_escape_string($sample_input);
	$sample_output=mysql_real_escape_string($sample_output);
	$hint=mysql_real_escape_string($hint);
	$source=mysql_real_escape_string($source);
	$sql="UPDATE `problem` set `title`='$title',`time_limit`='$time_limit',`memory_limit`='$memory_limit',
		`description`='$description',`input`='$input',`output`='$output',`sample_input`='$sample_input',`sample_output`='$sample_output',`hint`='$hint',`source`='$source',`spj`=$spj,`in_date`=NOW()
		WHERE `problem_id`=$id";
	@mysql_query($sql) or die(mysql_error());
	echo "Đã xong.<br>";	
	echo "<a href='../problem.php?id=$id'>Xem bài toán</a>";
}
?>
</body>
</html>

